#ifndef HARDWAREINTERFACEVIEW_HPP
#define HARDWAREINTERFACEVIEW_HPP

#include <QDockWidget>
#include <QStringList>
#include <QDebug>
#include <QMessageBox>
#include <QTime>

#include "qserialdevicewatcher/serialdevicewatcher.h"

namespace Ui {
    class HardwareInterfaceView;
}

/**
* @brief GUI Element visualizing the HardwareInterface state
* @details This GUI elements shows the current state of the HardwareInterface \n
* It provides a list of all available COM-Ports and allows the user to choose one and connect to it. \n
* Furthermore it is possible to trigger the Send manually or to Receive user specified data manually. \n
* A visualization of last sent / received values with corresponding timestamps is also shown.
*
* @class HardwareInterfaceView hardwareinterfaceview.hpp "hardwareinterfaceview.hpp"
*/
class HardwareInterfaceView : public QDockWidget {
    Q_OBJECT
public:
    /**
    * @brief HardwareInterfaceView Constructor
    *
    * @fn HardwareInterfaceView(QWidget *parent = 0)
    * @param parent
    */
    HardwareInterfaceView(QWidget *parent = 0);

    /**
    * @brief HardwareInterfaceView Destructor
    *
    * @fn ~HardwareInterfaceView
    */
    ~HardwareInterfaceView();

protected:
    /**
    * @brief Language change Event occured
    *
    * @fn void changeEvent(QEvent *e)
    * @param e
    */
    void changeEvent(QEvent *e);

private:
    Ui::HardwareInterfaceView *ui;
    SerialDeviceWatcher *serialWatcher;

private slots:
    /**
    * @brief Slot called when available serial Device list changes
    *
    * @fn void onSerialDevicesChanged(QStringList devices)
    * @param devices
    */
    void onSerialDevicesChanged(QStringList devices);

    /**
    * @brief Slot called when user toggles activation state
    *
    * @fn void on_cb_Activated_clicked()
    */
    void on_cb_Activated_clicked();

    /**
    * @brief Slot called when a new ComPort has been selected
    *
    * @fn void on_db_ComPort_currentIndexChanged(int index)
    * @param index
    */
    void on_db_ComPort_currentIndexChanged(int index);

    /**
    * @brief Slot called when Manual Receive has been triggerd by user
    *
    * @fn void on_btn_ManualReceive_clicked()
    */
    void on_btn_ManualReceive_clicked();

public slots:
    /**
    * @brief Slot called when the state of the HardwareInterface changes
    *
    * @fn void onHardwareInterfaceStateChanged(bool state)
    * @param state
    */
    void onHardwareInterfaceStateChanged(bool state);

    /**
    * @brief Slot called when it is not possible to open the given serial port
    *
    * @fn void onError(QString device, QString errorString)
    * @param device
    * @param errorString
    */
    void onError(QString device, QString errorString);

    /**
    * @brief Slot called when data has been read from serial port
    *
    * @fn void onDataRead(QString data)
    * @param data
    */
    void onDataRead(QString data);

    /**
    * @brief Slot called when data has been written to serial port
    *
    * @fn void onDataWritten(QString data)
    * @param data
    */
    void onDataWritten(QString data);

signals:
    /**
    * @brief Signal emitted when the user changes the state of the HardwareInterface
    * @details This signal is emitted when the user deactivates HWI or when he wants to change the port
    *
    * @fn void changeHardwareInterfaceState(QString name, bool state)
    * @param name
    * @param state
    */
    void changeHardwareInterfaceState(QString name, bool state);

    /**
    * @brief Signal emitted when user triggers the manual Send command
    *
    * @fn void manualSend()
    */
    void manualSend();

    /**
    * @brief Signal emitted when user triggers a manual receive
    *
    * @fn void manualReceive(QString data)
    * @param data
    */
    void manualReceive(QString data);
};

#endif // HARDWAREINTERFACEVIEW_HPP
